using System;

namespace PhillyCodeCamp.Domain.Validation
{
    [AttributeUsage(AttributeTargets.Property)]
    public class ValidDateAttribute : ValidationAttribute
    {
        public ValidDateAttribute()
            : this("is invalid date format")
        {
        }

        public ValidDateAttribute(string errMessage)
        {
            _message = errMessage;
        }

        protected override bool validate(object target, object rawValue)
        {
            if (rawValue == null)
            {
                return true;
            }
            var validDate = DateTime.MinValue;
            DateTime.TryParse(rawValue.ToString(), out validDate);
            return validDate != DateTime.MinValue;

        }
    }
}